package com.mq.core.factory;

import com.mq.core.container.AbstractMessageListenerContainer;
import com.mq.core.endpoint.RedisListenerEndpoint;


public abstract class AbstractRedisListenerContainerFactory<C extends AbstractMessageListenerContainer>
implements RedisListenerContainerFactory<C> {

    /**
     * 相关的一些配置
     */
    private int maxConsumer;
    private int retryTimes;

    @Override
    public C createListenerContainer(RedisListenerEndpoint endpoint) {
        C instance = createContainerInstance();
        instance.setMethod(endpoint.getMethod());
        instance.setBean(endpoint.getBean());
        instance.setQueueName(endpoint.getQueueName());
        instance.setId(endpoint.getId());
        instance.setMaxConsumer(getMaxConsumer());
        instance.setRetryTimes(getRetryTimes());
        instance.setRedisTemplate(endpoint.getRedisTemplate());
        return instance;
    }

    protected abstract C createContainerInstance();

    public int getMaxConsumer() {
        return maxConsumer;
    }
    public int getRetryTimes() {
        return retryTimes;
    }
    public void setMaxConsumer(int maxConsumer) {
        this.maxConsumer = maxConsumer;
    }
    public void setRetryTimes(int retryTimes) {
        this.retryTimes = retryTimes;
    }
}
